package storage
import (
	"github.com/gohouse/gorose/v2"
	_ "github.com/go-sql-driver/mysql"
	"github.com/Unknwon/goconfig"
)
var err error
var engin *gorose.Engin
func init() {
	var cfg, _= goconfig.LoadConfigFile("conf.ini")
	host , _ := cfg.GetValue("mysql", "host")
	port , _ := cfg.GetValue("mysql", "port")
	username , _ := cfg.GetValue("mysql", "username")
	password , _ := cfg.GetValue("mysql", "password")
	database , _ := cfg.GetValue("mysql", "database")
	dns:=username+":"+password+"@tcp("+host+":"+port+")/"+database+"?charset=utf8&parseTime=true"
	var config = &gorose.Config{Driver:"mysql",Dsn:dns}
	engin, err = gorose.Open(config)
}

//初始化DB
func DB() gorose.IOrm {
	return engin.NewOrm()
}